<?php
// Minifying JavaScript/CSS/HTML files. Part of mmvc library, https://code.google.com/p/mmvc/
// Part of mmvc library, https://code.google.com/p/mmvc/
// External Dependencies: ext/jsmin.php, ext/minify/*, ext/lessc.inc.php

/**
 * Minifies css/js/html/less.
 * @param $content Content
 * @param $type Supported types: 'css', 'js', 'html', 'less'. For unsupported type data is just returned as is.
 * @return Minified content.
 */
function minify( $type, $content )
{
	if ( $type == 'js' )
	{
		require_once( dirname(__FILE__).'/ext/jsmin.php' );
		$content = JSMin::minify( $content );
	}
	else if ( $type == 'less' )
	{
		require_once( dirname(__FILE__).'/ext/minify/CSS.php' );
		require_once( dirname(__FILE__).'/ext/lessc.inc.php' );
		$less = new \lessc();
		$content = Minify_CSS::minify( $less->parse($content), array('preserveComments'=>false) );
	}
	else if ( $type == 'css' )
	{
		require_once( dirname(__FILE__).'/ext/minify/CSS.php' );
		$content = Minify_CSS::minify( $content, array('preserveComments'=>false) );
	}
	else if ( $type == 'html' )
	{
		require_once( dirname(__FILE__).'/ext/minify/Minify_HTML.php' );
		$content = Minify_HTML::minify( $content );
	}
	return $content;
}

?>